#ifndef IMAGEACQUISITOR_H
#define IMAGEACQUISITOR_H

#include <QWidget>
#include <QLocalServer>
#include <QUrl>
#include <QSqlRecord>
#include <QTemporaryDir>
#include "detectorinterface.h"
class ThumbnailBarWidget;
class DcmFileFormat;
class QJsonObject;
class GeneratorInterface;
class DetectorInterface;
class ProcedureInterface;
class QTextEncoder;
class FtpClient;
class ImageEditDialog;

namespace Ui {
class ImageAcquisitor;
}

class ImageAcquisitor : public QWidget
{
    Q_OBJECT

public:
    explicit ImageAcquisitor(QWidget *parent = 0);
    ~ImageAcquisitor();

    bool isListening() const { return server->isListening(); }

public slots:
    void startAcq();
    void endAcq();

private slots:
    void onNewConnection();

private:
    void startLocalServer();
    void initDatabase();
    void initFileFormat();
    void insertStudyInfo();
    void loadPlugin();
    void showMessage(const QString &msg);
    void saveDoseValues(const double &kv, const double &ma, const double &ms, const double &mx);
    void updateDoseValues(const double &kv, const double &ma, const double &ms, const double &mx);
    void getImage();
    void getEnhancedImage();

    static void PluginProc(const QJsonObject &json, void *userData);

    Ui::ImageAcquisitor *ui;

    QTextEncoder *encoder;
    QLocalServer *server;
    ThumbnailBarWidget *barWidget;
    DcmFileFormat *ff;
    int curSeriesNo;
    int curImageNo;
    QString studyUid;
    QString seriesUid;
    QString imageUid;
    QString exam;
    QSqlRecord rec;

    ushort *imgBuf;
    int width;
    int height;

    FtpClient *ftp;
    ImageEditDialog *edit;
    DetectorConfig detConf;
    GeneratorInterface *genIntf;
    DetectorInterface *detIntf;
    ProcedureInterface *procIntf;
};

#endif // IMAGEACQUISITOR_H
